

export default class NotificationMgr extends cc.Component {

    /**系统通知消息 */
    private static NoticeArr: Array<string> = [];

    /**跑马灯滚屏内容 */
    private static NoticeScrolling: Array<any> = [];

    /**跑马灯列表消息 */
    private static SystemArr: Array<any> = [];

    /**系统通知消息id */
    private static NoticeArrId: Array<number> = [];

    public static FristGet: boolean = true;
    public static Isshow: boolean = true;

    private times: number = 60;

    private static _instance: NotificationMgr = null;

    public static getInstance(): NotificationMgr {
        if (this._instance == null) {
            this._instance = new NotificationMgr();
        }
        return this._instance;
    }


    /**跑马灯滚屏内容 */
    public static setNoticeScrolling(noticeScrolling) {
        this.NoticeScrolling.splice(0, 0, noticeScrolling)
    }

    /**跑马灯滚屏内容 */
    public static getNoticeScrolling() {
        return this.NoticeScrolling;
    }

    /**跑马灯列表消息 */
    public static setNoticeArr(noticeArr) {
        this.NoticeArr.push(noticeArr);
    }

    /**跑马灯列表消息 */
    public static getNoticeArr() {
        return this.NoticeArr;
    }

    /**系统通知消息 */
    public static setSystemArr(systemArr) {
        let data: Array<any> = [];
        for (const v of systemArr) {
            if (v.type == 1) {
                data.push(v);
            }
        }
        if (data) this.SystemArr.push(data);
    }

    /**系统通知消息 */
    public static getSystemArr() {
        return this.SystemArr;
    }

    /**系统通知消息ID */
    public static SetNoticeArrId(NoticeArrId) {
        this.NoticeArrId.push(NoticeArrId);
    }

    /**系统通知消息ID */
    public static GetNoticeArrId() {
        return this.NoticeArrId;
    }

    public getfixedMissage(times: number) {
        for (const v of NotificationMgr.getSystemArr()) {
            cc.gg.toastMgr.showScroll(v, null);
        }
        this.fixedStartScroll(times);
    }

    public fixedStartScroll(seconds: number) {
        this.times = seconds;
        let countDownHandler = () => {
            this.times--;
            // cc.log(this.times);
            if (this.times === 0) {
                this.getfixedMissage(seconds);
                this.unschedule(countDownHandler);
                return;
            }
        };
        this.schedule(countDownHandler, 1);
    }

    /**时间格式   分：秒 -- 00：00   */
    public static timesDate(): string {
        var date = new Date();//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
        return h + m;
    }

    /**返回数组中相邻的数 */
    public static adjoinNumber(arr) {
        var result = [],
            i = 0;
        result[i] = [arr[0]];
        arr.reduce(function (prev, cur) {
            cur - prev === 1 ? result[i].push(cur) : result[++i] = [cur];
            return cur;
        });
        return result;
    }
}
